package cn.kgc.taolun2.service;

import cn.kgc.taolun2.mapper.DetailMapper;
import cn.kgc.taolun2.pojo.Detail;
import cn.kgc.taolun2.pojo.DetailExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-05-22 11:56
 */
@Service
public class DetailServiceImpl implements DetailService {


    @Resource
    DetailMapper detailMapper;
    @Override
    public PageInfo<Detail> getPageInfo(Integer pageNum, Integer pageSize, Integer sortId) {
        PageHelper.startPage(pageNum,pageSize);
        DetailExample example=new DetailExample();
        DetailExample.Criteria criteria = example.createCriteria();

        if(sortId==0){
            List<Detail> details = detailMapper.selectByExample(null);
            PageInfo<Detail> pageInfo=new PageInfo<>(details);
            return pageInfo;
        }else{
            criteria.andSortidEqualTo(sortId);
            List<Detail> details = detailMapper.selectByExample(example);
            PageInfo<Detail> pageInfo=new PageInfo<>(details);
            return pageInfo;
        }
    }

    @Override
    public Integer addDetail(Detail detail) {
        return detailMapper.insert(detail);
    }

    @Override
    public Integer deleteDetail(Integer id) {
        return detailMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Detail selectById(Integer id) {
        return detailMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer updateDetail(Detail detail) {
        return detailMapper.updateByPrimaryKey(detail);
    }
}
